//
//  HealthAddViewController.m
//  parent
//
//  Created by yanzhen on 15/8/1.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "HealthAddViewController.h"
#import "AFAppClient.h"
#import "Config.h"

@interface HealthAddViewController ()
@property (weak, nonatomic) IBOutlet UITextField *inputView;
@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UILabel *lblNo;

@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;

@end

@implementation HealthAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"添加健康档案";
    UIView *accountLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 45, 45)];
    accountLeftView.backgroundColor = [UIColor clearColor];
    UIImageView *accountLeftImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"人-1"]];
    [accountLeftImg setFrame:CGRectMake(13, 13, 17, 19)];
    [accountLeftView addSubview:accountLeftImg];
    //_inputView.leftView = accountLeftView;
    //_inputView.leftViewMode = UITextFieldViewModeAlways;
    self.inputView.layer.borderColor = [UIColorMake(101, 101, 101) CGColor];
    self.inputView.layer.borderWidth = .25;
    self.inputView.layer.cornerRadius=2.0;
    
    self.nameField.layer.borderColor = [UIColorMake(101, 101, 101) CGColor];
    self.nameField.layer.borderWidth = .25;
    self.nameField.layer.cornerRadius=2.0;
    
    self.confirmBtn.layer.cornerRadius = 4.0;
    [self CustomBackButton];
}

- (IBAction)confirmAdd:(id)sender {
   
    if([self.nameField.text isEqualToString:@""]){
        [self showHudComplete:@"姓名不能为空" success:NO];
        return;
    }
    if([self.inputView.text isEqualToString:@""]){
        [self showHudComplete:@"身份证号不能为空" success:NO];
        return;
    }
    
    [self showHud:@"正在添加" isDim:YES];
    NSDictionary *params = @{@"uid":@([[Config Instance]getUID]),@"name":self.nameField.text,@"number":self.inputView.text};
    [[AFAppClient sharedManager]getWithURL:[NSString stringWithFormat:@"%@%@",SERVER_URL_NEW,kAddHealthNo] withParameters:params success:^(NSDictionary *responseObject) {
        if([[responseObject objectForKey:@"code"]integerValue]==1){
            [self showHudComplete:@"添加成功" success:YES];
            [[NSNotificationCenter defaultCenter] postNotificationName:kAddHealth object:@YES];
            [self.navigationController popViewControllerAnimated:YES];
        }else {
            
            [self showHudComplete:@"添加失败" success:NO];
        }
           } failure:^(NSError *error) {
        [self showHudComplete:@"网络连接失败" success:NO];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
